package LifeTest;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

import com.structure.UF;

public class UFtest {
	public static void main(String[] args) throws FileNotFoundException {
		int p,q,num;
		
		Scanner scan = new Scanner(new FileInputStream("D:\\eclipse\\workspace\\Algorithm\\src\\algs4-data\\tinyUF.txt"));
		num = scan.nextInt();
		UF uf = new UF(num);
		
		for (int i = 0; i < num; i++) {
			p = scan.nextInt();
			q = scan.nextInt();
			uf.union(p, q);
		}
		System.out.println(uf.count());
	}
}
